import java.util.Set;

public class Text2 {
    // 字符串分割
    public boolean wordBreak(String s, Set<String> dict) {
        if(s == null )
            return false;

        boolean[] dp = new boolean[s.length() + 1];
        dp[0] = true;

        // 状态转换
        for(int i = 1; i < s.length() + 1; i++){
            for(int j = i - 1; j >= 0; j--){
                if(dp[j] && dict.contains(s.substring(j,i))){
                    dp[i] = true;
                    break;
                }
            }
        }

        return dp[s.length()];
    }
}
